package drt.toolbox.mouse;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;

import drt.toolbox.screen.Pixel;

public class Mouse {

	private Robot robot;

	public Mouse() {
		try {
			robot = new Robot();
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}

	public void move(int x, int y) {
		try {
			robot.mouseMove(x, y);
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void move(Pixel pixel) {
		move(pixel.x, pixel.y);
	}

	public void wheelUp() {
		try {
			robot.mouseWheel(10);
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void wheelDown() {
		try {
			robot.mouseWheel(-10);
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void click(int x, int y, int clicks) {
		try {
			robot.mouseMove(x, y);
			for (int i = 0; i < clicks; i++) {
				robot.mousePress(InputEvent.BUTTON1_MASK);
				robot.mouseRelease(InputEvent.BUTTON1_MASK);
			}
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void click(Pixel pixel) {
		click(pixel.x, pixel.y, 1);
	}

	public void click(Pixel pixel, int clicks) {
		click(pixel.x, pixel.y, clicks);
	}

}
